package tom.oauth2.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZHUFEIFEI
 */
@RestController
public class HelloController {

    @GetMapping("/hi")
    public Object hi() {
        return "hello world";
    }

    @PreAuthorize("hasAuthority('me')")
    @GetMapping("/hi/{name}")
    public Object hi(@PathVariable("name") String name) {
        return "hello " + name;
    }

    @PreAuthorize("#oauth2.hasScope('hello')")
    @GetMapping("/hello")
    public Object scope() {
        return "hello scope";
    }

    @PreAuthorize("#oauth2.hasScope('hello') and hasRole('admin_role')")
    @GetMapping("/role")
    public Object role() {
        return "role and scope";
    }
}
